package be.quadreg.dojo.model.entity;

import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Id;

import be.quadreg.dojo.persistence.GenericDAO;

import com.googlecode.objectify.Key;

public class Member {
	@Id
	private Long id;

	private String firstName;
	private String surName;
	private Date dateOfBirth;

	private Set<Key<MemberAttribute>> memberAttributeKeys;

	public Member() {
		memberAttributeKeys = new HashSet<Key<MemberAttribute>>();
	}

	public Member(String firstName, String surName, Date dateOfBirth) {
		this();
		this.firstName = firstName;
		this.surName = surName;
		this.dateOfBirth = dateOfBirth;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public boolean addAttribute(MemberAttribute memberAttribute) {
		Key<MemberAttribute> maKey = GenericDAO.getInstance().persistMemberAttribute(
				memberAttribute);
		return memberAttributeKeys.add(maKey);
	}

	public Collection<MemberAttribute> getMemberAttributes() {
		return GenericDAO.getInstance().getMemberAttributes(memberAttributeKeys);
	}


	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getSurName() {
		return surName;
	}

	public void setSurName(String surName) {
		this.surName = surName;
	}

	public Date getDateOfBirth() {
		return dateOfBirth;
	}

	public void setDateOfBirth(Date dateOfBirth) {
		this.dateOfBirth = dateOfBirth;
	}

	@Override
	public String toString() {
		return "Member [id=" + id + ", firstName=" + firstName + ", surName="
				+ surName + ", dateOfBirth=" + dateOfBirth
				+ ", memberAttributes=" + memberAttributeKeys + "]";
	}

}
